package com.walnut.lom_system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.walnut.lom_system.common.annotation.DoLog;
import com.walnut.lom_system.common.lang.Const;
import com.walnut.lom_system.common.lang.OperateTypeContains;
import com.walnut.lom_system.common.lang.ResultInfo;
import com.walnut.lom_system.common.util.ResultInfoUtil;
import com.walnut.lom_system.domain.form.EmployInfoForm;
import com.walnut.lom_system.domain.form.EmployInfoSearchForm;
import com.walnut.lom_system.domain.vo.EmployInfoVo;
import com.walnut.lom_system.service.EmployInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author chenhetao
 * @version 1.0
 * @className AdminEmployController
 * @description TODO
 * @date 2022/4/17 00:10
 */
@RestController
@Api(tags = "招新及换届相关接口")
@RequestMapping("/admin/employ")
public class AdminEmployController {

    private static final Logger LOG = LoggerFactory.getLogger(HelloWorldController.class);

    @Autowired
    private EmployInfoService employInfoService;

    @GetMapping("/{id}")
    @ApiOperation("管理员通过id获取指定报名者")
    @DoLog(operateModule = "OPERATE", operateType = OperateTypeContains.OPERATE_VISIT, operateDesc = "管理员查询报名者操作")
    public ResultInfo<EmployInfoVo> queryEmployee(@PathVariable("id") long id){
        EmployInfoVo employInfoVo = employInfoService.getEmployee(id);
        return ResultInfoUtil.buildSuccess(employInfoVo);
    }

    @GetMapping("/list")
    @ApiOperation("管理员查询报名者列表")
    @DoLog(operateModule = "OPERATE", operateType = OperateTypeContains.OPERATE_VISIT, operateDesc = "查询报名者列表操作")
    public ResultInfo queryEmployeeList(@RequestBody @Validated EmployInfoSearchForm employInfoSearchForm){
        Page<EmployInfoVo> employInfoVoList = employInfoService.getList(employInfoSearchForm);
        return ResultInfoUtil.buildSuccess(employInfoVoList);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("管理员删除报名者")
    @DoLog(operateModule = "OPERATE", operateType = OperateTypeContains.OPERATE_VISIT, operateDesc = "删除报名者操作")
    public ResultInfo deleteEmployee(@PathVariable("id")@NotNull long id){
        //TODO 代码
        int i = employInfoService.deleteEmployee(id);

        if (i == Const.OP_SUCCESS) {
            return ResultInfoUtil.buildSuccess("删除成功");
        } else {
            return ResultInfoUtil.buildError("删除失败");
        }
    }

    @PutMapping("/{id}")
    @ApiOperation("管理员更新报名者")
    @DoLog(operateModule = "OPERATE", operateType = OperateTypeContains.OPERATE_VISIT, operateDesc = "管理员更新报名者")
    public ResultInfo updateEmployee(@PathVariable("id") long id,@RequestBody @Validated EmployInfoForm employInfoForm){
        int i = employInfoService.updateEmployee(id,employInfoForm);
        return ResultInfoUtil.buildSuccess("success");
    }
}
